<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>jQuery UI Example Page</title>
                <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
                <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
                
                <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/smoothness/jquery-ui.css" type="text/css" />
                <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" type="text/css" />
                
                <script>
	$(function() {
		$( "#tabs" ).tabs({
			ajaxOptions: {
				error: function( xhr, status, index, anchor ) {
					$( anchor.hash ).html(
						"Couldn't load this tab. We'll try to fix this as soon as possible. " +
						"If this wouldn't be a demo." );
				}
			}
		});
	});
	</script>
                

		
	
			
	</head>
        <body>
            
            <div class="demo">

<div id="tabs">
	<ul>
		<li><a href="#vecinos">Mis Vecinos</a></li>
		<li><a href="#amigos">Mis Amigos</a></li>
                
		
	</ul>
	
    <div id="vecinos">
						
                                               
                                                <?php
													$res = @mysql_query("select lat from direccion_usuarios where user_name='$username'");
													$row = mysql_fetch_array($res);
                                                    $center_lat=$row['lat'];
													$res = @mysql_query("select lng from direccion_usuarios where user_name='$username'");
													$row = mysql_fetch_array($res);
                                                    $center_lng=$row['lng'];
                                                    $radius='200'; //in kms

                                                   $result = @mysql_query("SELECT usuarios.uid_facebook as uid, usuarios.user_name as nombre, direccion_usuarios.lat as lat, direccion_usuarios.lng as lng, (SELECT (acos(sin(radians('$center_lat')) * sin(radians(lat)) + cos(radians('$center_lat')) * cos(radians(lat)) * cos(radians('$center_lng')- radians(lng))) * 6378)) AS distance FROM direccion_usuarios, usuarios WHERE (direccion_usuarios.user_name=usuarios.user_name and direccion_usuarios.user_name!='$username')  HAVING distance < '$radius' ORDER BY distance;");
														

                                                    while($row = mysql_fetch_array($result))
                                                    {
                                                        echo '<p><img src="https://graph.facebook.com/'.$row['uid'].'/picture">';
                                                        echo '&nbsp;<a href="https://www.facebook.com/profile.php?id='.$row['uid'].
                                                        '">'.utf8_encode($row['nombre']).'</a> - '.round($row['distance'],2).' kms</p>';
                                                    }
                                                   ?>
						
					</div>
    <div id="amigos"> 
						<?php
						$result = @mysql_query("SELECT usuarios.user_name as ff, usuarios.uid_facebook as fuid FROM usuarios, amigos_facebook as friend WHERE friend.uid_facebook = '$uid' and friend.id_amigo=usuarios.uid_facebook GROUP BY(usuarios.user_name)");

						while($row = mysql_fetch_array($result))
						  {
						echo '<p><img src="https://graph.facebook.com/'.$row['fuid'].'/picture">';
						echo '&nbsp;<a href="https://www.facebook.com/profile.php?id='.$row['fuid'].'">'.utf8_encode ($row['ff']).'</a></p>';
						  }

						$result = @mysql_query("SELECT other.user_name as ff, other.uid_facebook as fuid FROM usuarios as other, amigos_facebook as friend WHERE friend.uid_facebook = '$uid' and friend.id_amigo=other.uid_facebook GROUP BY(other.uid_facebook) ORDER BY(other.uid_facebook) desc");
						echo '<script>';
						echo 'var fuids = [];';
						while($row = mysql_fetch_array($result))
						  {
						echo 'fuids.push('.$row['fuid'].');';
						  }

						echo '</script>';
						?>
					</div>
</div>

</div><!-- End demo -->



	
	</body>
</html>
